package com.itqf.controller;

import com.itqf.bean.Bill;
import com.itqf.bean.Param;
import com.itqf.service.BillService;
import com.itqf.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * projectName: springmvc2103
 *
 * @author: 赵伟风
 * time: 2021/7/5 20:31
 * description:
 *
 * mvc设计模式以及java的三层架构!
 *
 *    controller
 *       1.接受请求参数
 *          password = root
 *       2.调用service
 *         vo = service
 *       3.响应数据
 *        return vo;
 *    service
 *       1.处理请求参数
 *          password  md5密文
 *       2.调用mapper curd
 *       3.处理数据库返回数据
 *           int rows = 1 / 0;
 *           ResultVo.OK(1)
 *    mapper
 *       curd
 *       int delete
 *
 */
@RestController
@RequestMapping("bill")
public class BillController {

    @Autowired
    private BillService billService;

    /**
     * 供应商展示
     * 		i. 供应商下拉列表展示接口
     * 			1. url    /bill/providers
     * 			2. method  get
     * 			3. request  无
     * 			4. response
     * [{},{}]
     */
    @GetMapping("providers")
    public Object providers(){
        //1.参数接受
        //2.调用service
        ResultVO resultVO = billService.findProviders();
        //3.响应数据

        return resultVO;
    }



    /**
     * 账单展示接口
     * @return
     */
    @GetMapping("list")
    public Object billList(){

        ResultVO resultVO = billService.findBills();

        return resultVO;
    }


    /**
     * 账单保存功能
     * @param bill
     * @return
     */
    @PostMapping(value = "save",consumes = "application/json;charset=utf-8")
    public Object save(@RequestBody Bill bill){

        ResultVO resultVO = billService.saveBill(bill);

        return resultVO;
    }


    /**
     * 修改账单
     * @param bill
     * @return
     */
    @PostMapping(value="update",consumes = "application/json;charset=utf-8")
    public Object update(@RequestBody Bill bill){

        ResultVO resultVO  = billService.updateBill(bill);

        return resultVO;
    }


    /**
     * 查看账单接口
     * @param id
     * @return
     */
    @GetMapping("info")
    public Object info(int id){

        ResultVO resultVO = billService.infoBill(id);

        return resultVO;
    }


    @GetMapping("remove")
    public Object remove(int id){

        ResultVO resultVO = billService.removeBill(id);

        return resultVO;
    }



    @PostMapping("search")
    public Object search(@RequestBody Param param){

        ResultVO resultVO = billService.searchBill(param);

        return resultVO;
    }




}
